package com.oragraph.data.group.impl;

import org.python.util.PythonInterpreter;

import com.oragraph.data.group.Group;
import com.oragraph.data.instance.Instance;

public class GroupFactoryHelper {
	
	private static PythonInterpreter _interpreter;
	
	static {
		_interpreter=new PythonInterpreter();
	}
	
	public static boolean passesFilter(Group group, Instance instanceToAdd) {
		String filterString=group.getMutableProperties().get("filter");
		if (!filterString.equals("")) {		
			_interpreter.set("node", instanceToAdd);
			int filterResult=-1;
			_interpreter.set("result", filterResult);					
			_interpreter.exec(filterString);
			filterResult=_interpreter.get("result").asInt();
			if (filterResult==1) return true;
			else if (filterResult==0) return false;
			// TODO: Error handling
			return false;
		}
		else {
			return true;
		}
		
	}

}
